﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using UIT.ScrumTool.Client.Utilities.Team;
using UIT.ScrumTool.Client.View.Project;
using UIT.ScrumTool.Client.Controller;


namespace UIT.ScrumTool.Client.View.Team
{
    /// <summary>
    /// Interaction logic for dxwUserInfo.xaml
    /// </summary>
    public partial class dxwUserInfo : DXWindow
    {

        public dxwUserInfo()
        {
            InitializeComponent();
        }

        // Show Member Info
        public void ShowMemberInfo(MemberInfo memberInfo)
        {
            this.tbMail.Text = memberInfo.Email;
            this.tbLoginName.Text = memberInfo.LoginName;
            this.cbRole.SelectedIndex = memberInfo.UserRole;
        }

        // Change Member Role
        private void cbRole_SelectedIndexChanged(object sender, RoutedEventArgs e)
        {
            MemberInfo memberSelected = uctrlProject._listViewMember.SelectedItem as MemberInfo;
            if (cbRole.SelectedIndex != memberSelected.UserRole)
            {
                // Update Member Role
                ProjectUserCtrl.ProjectUserUpdateRole(memberSelected.ProjectUserId, cbRole.SelectedIndex);
                MemberInfo lstMemberItem = uctrlProject.lstMember.Find(mem => mem.ProjectUserId == memberSelected.ProjectUserId);
                lstMemberItem.UserRole = cbRole.SelectedIndex;

                // Refresh Member List
                uctrlProject._listViewMember.ItemsSource = uctrlProject.lstMember;
                uctrlProject._listViewMember.Items.Refresh();
            }
        }
    }
}
